﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PlutoStudio.Net.Configuration
{
    public class ClientSection:System.Configuration.ConfigurationSection
    {
        [System.Configuration.ConfigurationProperty("Address", DefaultValue = "0.0.0.0")]
        public string Address
        {
            get
            {
                return this["Address"] as string;
            }
            set
            {
                this["Address"] = value;
            }
        }

        public System.Net.IPAddress IPAddress
        {
            get
            {
                System.Net.IPAddress address;
                if (!System.Net.IPAddress.TryParse(Address,out address))
                {
                   address= System.Net.Dns.GetHostAddresses(Address).First();
                }
                return address;
            }
            set
            {
                Address = value.ToString();
            }
        }

        [System.Configuration.ConfigurationProperty("Port", DefaultValue = 0)]
        public int Port
        {
            get
            {
                return (int)this["Port"];
            }
            set
            {
                this["Port"] = value;
            }
        }

        [System.Configuration.ConfigurationProperty("BufferSize", DefaultValue = 8192)]
        public int BufferSize
        {
            get
            {
                return (int)this["BufferSize"];
            }
            set { this["BufferSize"] = value; }
        }

    }
}
